package com.grape.dp.observer.spring.controller;

import cn.hutool.json.JSONObject;
import com.grape.dp.observer.spring.event.OrderMessageEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述:OrderController
 * @author: myx
 * @date: 2019/7/29 0029
 * Copyright © 2019-grape. All rights reserved.
 */
@RestController
public class OrderController {
    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping("/sendMsg")
    public String sendMsg() {
        //1.定义发送消息内容
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "599982811@qq.com");
        jsonObject.put("phone", "18888888888");
        jsonObject.put("text", "设计模式");
        OrderMessageEvent orderMessageEvent = new OrderMessageEvent(this, jsonObject);
        applicationContext.publishEvent(orderMessageEvent);
        return "success";
    }
}
